﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace IT_Project_Monopoly
{
    public partial class PlayerList : System.Web.UI.UserControl
    {
        public void addPlayer(string name, float money, int points)
        {
            PlayerListItem player = (PlayerListItem)LoadControl("PlayerListItem.ascx");
            player.PlayerName = name;
            player.PlayerMoney = money;
            player.PlayerPoints = points;
            playersList.Controls.Add(player);
        }
        
        public void activateNext()
        {
            int playerCount = playersList.Controls.Count;

            if (playerCount > 0)
            {
                int indexToActivate = (int.Parse(activeIndex.InnerText) + 1) % playerCount;
                foreach(PlayerListItem pItem in playersList.Controls) pItem.setActive(false);
                ((PlayerListItem)this.playersList.Controls[indexToActivate]).setActive(true);
                activeIndex.InnerText =  indexToActivate.ToString();
            }
        }

        public PlayerListItem getActivePlayer()
        {
            return (PlayerListItem)this.playersList.Controls[int.Parse(activeIndex.InnerText)];
        }

        public int getActiveIndex()
        {
            return int.Parse(activeIndex.InnerText);
        }
    }
}